package com.lej.dataservice.club.bean

import com.google.gson.reflect.TypeToken
import com.lej.core.utils.cache.AppACache
import com.lej.dataservice.club.http.baseApiService
import com.lej.dataservice.club.http.checkData
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

///弹窗等文案
data class TipsBean(
    val content: String,
    val title: String
)

enum class TipsKey {
    sys_micro_phone,
    sys_storage,
    store,
    sys_gps,
    sys_notice,
    go_login,
    skip_paper,
    why_base_photo
    ;

    suspend fun tips(): TipsBean? {
        var bean = tipsMap?.get(name)
        if (bean == null)
            kotlin.runCatching {
                val map = baseApiService.toastconf()?.checkData()
                tipsMap = map
                bean = tipsMap?.get(name)
            }
        return bean
    }

    companion object {
        fun update() {
            GlobalScope.launch {
                kotlin.runCatching {
                    tipsMap = baseApiService.toastconf()?.checkData()
                }
            }
        }
    }
}

var tipsMap by AppACache(object : TypeToken<HashMap<String, TipsBean>>() {}, "cache")
